<template>
	<view class="container">
		<view class="navbar">
			<view v-for="(item, index) in logisticsData" :key="index" class="nav-item"
				:class="{current: tabCurrentIndex === index}" @click="tabClick(index)">
				<text>快递{{index+1}}</text>
			</view>
		</view>
		<view class="product-list">
			<view class="item">
				<view class="left">
					<image class="goods-img" :src="order.items[0].thumbnail"></image>
					<view class="goods-num">
						{{sumNum}}件
					</view>
				</view>
				<view class="right">
					<view class="titleStatus">
						<text>{{statusData[order.status]}}</text>
					</view>
					<text class="title more-t">物流公司：{{logisticInfo.name}}</text>
					<view class="title more-t">物流单号：{{logisticInfo.sn}}<copy-button style="display: inline-block;" :content="logisticInfo.sn"></copy-button></view>
				</view>
			</view>
				
		</view>
		<view style="padding: 0 20upx;background-color: #fff;">
			<lee-logistics height="calc(100% - 170px)" :logisticInfo="logisticInfo.trackList" />
		</view>
		
	</view>
</template>

<script>
	import LeeLogistics from '@/components/lee-logistics/lee-logistics.vue'
	import copyButton from '../../components/copy.vue'
	import {
		getOrderDetail,
		getLogistics,
		getOrderLogs
	} from '@/api/order/detail.js';
	import {
		getAllStatus,
	} from '../../api/order/order.js'
	import {h5Copy} from '../../common/utils/func.js'
	export default {
		components: {
			copyButton,
			LeeLogistics
		},
		data() {
			return {
				navList: [{
						status: 'unShipped',
						text: '待发货',
						loadingType: 'more',
						orderList: [],
						page: 1,
						num: 0
					},
					{
						status: 'shipped',
						text: '待收获',
						loadingType: 'more',
						orderList: [],
						page: 1,
						num: 0
					}
				],
				tabCurrentIndex: 0,
				id: '',
				order: {
					ext: {},
					items: {},
					master: {}
				},
				logisticsData: [],
				sumNum: 0,
				integralRule:uni.getStorageSync('integralRule'),
				logisticInfo: {},
				statusData: []
			
			};
		},
		onLoad(options) {
			this.id = options.id
			this.showOrderDetail(options.id)
			this.getStatusData()
		},
		
		methods: {
			copySn(sn) {
			    //#ifdef MP
				uni.setClipboardData({
					data: sn,
					success: () => {
						uni.showToast({
							icon: "success",
							title: '复制成功'
						})
					}
				})
			    // #endif
			    // #ifdef H5
			    if(h5Copy(sn)){
			        uni.showToast({
			            icon: "success",
			            title: '复制成功'
			        })
			    }
			    // #endif
			
			},
			getStatusData() {
				getAllStatus().then(res => {
					if (res.code === 0) {
						this.statusData = res.data
					}
				})
			},
			loadLogistics() {
				getLogistics({
					id: this.order.id
				}).then(res => {
					if (res.code === 0) {
						this.logisticsData = res.data
						this.logisticInfo = res.data[0]
						if(this.logisticInfo.trackList.length == 0) {
							this.$util.msg('暂无物流信息，如有疑问请联系供应商')
						}
						console.log(this.logisticInfo)
						
					}
				})
			},
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
				this.logisticInfo = this.logisticsData[this.tabCurrentIndex]
			},
			showOrderDetail(id) {
				getOrderDetail({
					sn: id
				}).then(res => {
					if (res.code == 0) {
						let datas = res.data
						this.sumNum = 0
						for(let i = 0; i < datas.items.length;i++) {
							this.sumNum += +datas.items[i].num
						}
						this.order = datas;
						this.loadLogistics()
					} else {
						this.$util.msg(res.message)
					}
				})
			},
		}




	}
</script>

<style lang="scss">
	page,
	.content {
		background:#fff;
		height: 100%;
	}

	.container {
		background: #fff;
		height: 100%;
	}

				.copy{
					background: #ECECEC;
					border-radius: 20rpx;
					margin-left: 20rpx;
					min-width: 80rpx;
					text-align: center;
					width: fit-content;
				}
				.titleStatus {
					color: #ec8d98;
					font-size: 34upx;
					margin-bottom: 20upx;
				}
				.title {
					font-size: $font-base;
					color: $font-color-dark;
					margin: 10upx 0;
					// line-height: 42rpx;
				}
				
	.navbar {
		display: flex;
		height: 80rpx;
		// padding: 0 10rpx;
		padding-left: 10rpx;
		background: #fff;

		box-shadow: 0 1px 5px rgba(0, 0, 0, .06);
		z-index: 10;
		min-width: 100%;
		width: auto;
		overflow-x: scroll;
		white-space: nowrap;

		.nav-item {
			flex: 1;
			width: auto;
			margin-right: 10rpx;
			line-height: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: $my-font-size-base;
			color: $font-color-dark;
			position: relative;

			text {
				width: 100%;
				text-align: center;
			}

			&.current {
				color: $base-color;

				// &:after {
				// 	content: '';
				// 	position: absolute;
				// 	left: 50%;
				// 	// left: 0;
				// 	bottom: 0;
				// 	transform: translateX(-50%);
				// 	// width: 44px;
				// 	width: 100%;
				// 	height: 0;
				// 	border-bottom: 2px solid $base-color;
				// }
			}

			/deep/.uni-badge {
				line-height: normal;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.badge {
				position: absolute;
				top: 0;
				right: -10rpx;
				color: #fff;
				background-color: $base-color;
				/* #ifdef MP */
				border-radius: 100px;
				/* #endif */

				text {
					/* #ifdef MP */
					color: #fff;
					background-color: $base-color;
					/* #endif */
				}
			}
		}
	}
			.product-list {
				// padding: 10rpx;
				border-top: 1px solid $my-border-color-grey;
				border-bottom: 1px solid $my-border-color-grey;
				position: relative;
				.goods-num {
					position: absolute;
					    top: 154upx;
					    color: #fff;
					    left: 134upx;
					    background-color: #646464;
					    padding: 10upx 20upx;
					    opacity: 0.8;
					    border-radius: 30upx;
					    font-size: 30upx;
				}
				.item {
					display: flex;
					border-bottom: 1px solid $my-border-color-grey;
					background-color: $my-bg-color;
					padding: 10rpx 20rpx;

					&:last-child {
						border-bottom: none;
					}

					.left {
						width: 200rpx;
						height: 200rpx;
						margin-right: 20rpx;
						.goods-img {
							width: 200upx;
							height: 200upx;
							
						}
						image {
							width: 100%;
							height: 100%;
						}
					}

					.right {
						flex: 1;
						// width: 550rpx;
						display: flex;
						justify-content: inherit;
						flex-direction: column;

						.name {
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
							overflow: hidden;
							// line-height: 40rpx;
							// height: 80rpx;
							word-break: break-all;
						}

						.bottom {
							display: flex;
							// margin-top: 14rpx;

							.price {
								display: flex;
								flex-direction: column;
								color: $my-text-color-red;
								line-height: 32rpx;
							}

							.num {
								margin: auto;
								margin-right: 0;
								margin-top: 0;
							}
						}

						.action {
							// margin-top: 14rpx;
							width: fit-content;
							height: fit-content;
							padding: 4rpx 16rpx;
							text-align: center;
							font-size: $my-font-size-sm;
							color: $font-color-dark;
							background: #fff;
							border-radius: 20px;
							border: 0.5px solid #C0C4CC;
						}
					}
				}
			}
	
</style>
